package com.traffic.between.adaptor;

import java.util.Date;
import org.apache.log4j.Logger;
import com.traffic.between.annotation.ChooseProvider;
import com.traffic.between.config.BetweenProperties;
import com.traffic.between.config.OrderInfoContext;
import com.traffic.between.redis.running.BsmOrderResultExecutor;
import com.traffic.between.service.HuaLeiHuiServiceImpl;


import com.traffic.managent.service.order.bean.OrderBean;

import net.sf.json.JSONObject;

@ChooseProvider(channel = "hualh")
public class HuaLeiHuiAdaptor implements IAdaptor {

	private static Logger log = Logger.getLogger(HuaLeiHuiAdaptor.class);
	private static String HOST_CALLBACK_URL = BetweenProperties.CALLBACK_URL;//回调地址
	public void order() {
		OrderBean orderBean = OrderInfoContext.getContext();
		orderBean.setSendTime(new Date());
		
		String productbingdingId = orderBean.getProductCode();
		String phone = orderBean.getPhoneNo();
		String cstmOrderNo = orderBean.getIds();
		String notifyUrl = HOST_CALLBACK_URL+"Hualh";//回调地址
		log.info("between- 花蕾荟订单HuaLeiHuiService.order() 订购请求productbingdingId:" + productbingdingId+",phone:"+phone+",cstmOrderNo"+cstmOrderNo+",notifyUrl"+notifyUrl);
		String result = HuaLeiHuiServiceImpl.service.order(productbingdingId, phone, cstmOrderNo, notifyUrl);
		
		JSONObject json = JSONObject.fromObject(result);

		int code = json.getInt("code");

		if ("0".equals(String.valueOf(code))) {
			orderBean.setStatus("10");
			orderBean.setMessage(json.getString("msg"));
			orderBean.setErrorMsg(json.getString("msg"));
		} else {
			orderBean.setStatus("8");
			orderBean.setMessage(json.getString("msg"));
			orderBean.setErrorMsg(json.getString("msg"));
		}
	
		BsmOrderResultExecutor.service.setOrder(orderBean);
	}

	
}
